const {Model, DataTypes} = require('sequelize');
const sequelize = require('../config/db');

class UserAction extends Model {}

UserAction.init({
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    user_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'users',
            key: 'id'
        }
    },
    goods_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: 'goods',
            key: 'id'
        }
    },
    action_type: {
        type: DataTypes.ENUM('view', 'collect', 'share'),
        allowNull: false,
        comment: '行为类型：浏览、收藏、分享'
    },
    action_time: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW
    }
}, {
    sequelize,
    modelName: 'user_actions',
    tableName: 'user_actions',
    timestamps: false,
    indexes: [{
        fields: ['user_id', 'action_type']
    }]
});

module.exports = UserAction;